
#include "tasks.h"

#include "serial.h"

#include "core.h"

#define BUSYWAIT_COUNTER 100000

#define busywait() \
  do { \
      unsigned int i; \
      for (i = 0; i < BUSYWAIT_COUNTER; i++); \
  } while (0)


void 
process_print(int argc, char **argv)
{
    char *s = argc ? argv[0] : "A";
    while (1) {
        kprintf(s);
        busywait();
    }
}

void 
process_yield(int argc, char **argv)
{
    char *s = argc ? argv[0] : "C";
    while(1) {
        kprintf(s);
       *((unsigned char*)0x22f30000) = 'C';
       yield();
    }
}
// 
void process_conflict_A(int argc, long **argv){
    unsigned long *address = 0xB0000000;
    //unsigned long *address = argc ? argv[0] : 0;
    while(1){	
     unsigned  long read_value = *address;
	*address = 42;
	unsigned long write_value = *address;
	kprintf("Ich bin Prozess ’A’ und lese den Wert %d und schreibe den Wert %d ...",read_value, write_value);
	//busywait();
	yield();
    }
}

void process_conflict_Z(int argc, long **argv){
    unsigned long *address = 0xB0000000;
    kprintf("Konflikadresse: %x\n",address);
    //unsigned long *address = argc ? argv[0] : 0;
      while(1){
	unsigned long read_value = *address;
	  *address = 23;
	  unsigned long write_value = *address;
	  kprintf("Ich bin Prozess ’Z’ und lese den Wert %d und schreibe den Wert %d ...",read_value, write_value);
	  //busywait();
	  yield();
      }
}
